//
//  main.swift
//  PerfectTemplate
//
//  Created by Kyle Jessup on 2015-11-05.
//	Copyright (C) 2015 PerfectlySoft, Inc.
//
//===----------------------------------------------------------------------===//
//
// This source file is part of the Perfect.org open source project
//
// Copyright (c) 2015 - 2016 PerfectlySoft Inc. and the Perfect project authors
// Licensed under Apache License v2.0
//
// See http://perfect.org/licensing.html for license information
//
//===----------------------------------------------------------------------===//
//

import PerfectHTTP
import PerfectHTTPServer
import PerfectSession
import PerfectSessionMySQL
import PerfectLib

SessionConfig.name = "MySQLDrivers"
SessionConfig.idle = 60
SessionConfig.IPAddressLock = true
SessionConfig.userAgentLock = true

MySQLSessionConnector.host = "127.0.0.1"
MySQLSessionConnector.port = 3306
MySQLSessionConnector.username = "root"
MySQLSessionConnector.password = "123456"
MySQLSessionConnector.database = "test"
MySQLSessionConnector.table = "sessions"

let sessionDirver = SessionMySQLDriver()

let server = HTTPServer()
server.serverName = "localhost"
server.serverPort = 8181
server.addRoutes(makeRoutes())
server.setRequestFilters([sessionDirver.requestFilter])
server.setResponseFilters([sessionDirver.responseFilter])
do {
    // Launch the HTTP server.
    try server.start()
} catch PerfectError.networkError(let err, let msg) {
    print("Network error thrown: \(err) message:\(msg)")
}
//try HTTPServer.launch(name: "localhost",
//                      port: 8181,
//                      routes: makeRoutes(),
//                      responseFilters: [
//                        (PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)])

